<template>
  <div class="login">
    <van-nav-bar title="注册" left-arrow  @click-left="onClickLeft"/>
    <van-form @submit="onSubmit">
     <van-field
        v-model="phone"
        name="phone"
        label="手机号"
        placeholder="手机号"
        :rules="[{ required: true, message: '请填写手机号' }]"
      />
      <van-field
        v-model="nickname"
        name="nickname"
        label="昵称"
        placeholder="昵称"
        :rules="[{ required: true, message: '请填写昵称' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">注册</van-button>
      </div>
    </van-form>
    <router-link to="/login">已有账号？立即登录</router-link>
  </div>
</template>
<script>
export default {
  data() {
    return {
      phone: "",
      nickname:'',
      password: ""
    };
  },
  methods: {
    onSubmit(values) {
      this.$http.post('register',values).then(res=>{
          this.$router.push('/login');
      })
    },
    onClickLeft(){
      this.$router.go(-1);
    }
  }
};
</script>
<style >
.router-link-active {
  color: blue;
}
.login {
  text-align: center;
}
</style>